import 'package:flutter/material.dart';

import '../../helper/utils/util.dart';
import 'index.dart';

class AppLogPage extends StatelessWidget {
  const AppLogPage({super.key});

  // 主视图
  Widget _buildView() {
    var state = AppLogController().state;
    return TPTabBarView(
      controller: state.tabCtrl,
      pageBuilder: (context, index) {
        List<String> list = state.logs;
        if (state.tabCtrl.index.value == 1) {
          list = state.errors;
        }
        return ListView.builder(
          itemBuilder: (context, index) {
            var m = list[index];
            return ListTile(
              subtitle: Text(m),
            );
          },
          itemCount: list.length,
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: detailAppBar(context,
          title: '日志异常捕捉',
          bottom: PreferredSize(
              preferredSize: Size.fromHeight(44.r),
              child: TPTabBar(controller: AppLogController().state.tabCtrl))),
      body: SafeArea(
        child: _buildView(),
      ),
    );
  }
}
